@inject AuthenticationStateProvider AuthState

<AuthorizeView>
  <Authorized>
    Hello, @_username!
  </Authorized>
</AuthorizeView>

@code
{
  private string _username = "Anonymous User";

  protected override async Task OnInitializedAsync()
  {
    var state = await AuthState.GetAuthenticationStateAsync();

    _username =
      state.User.Claims
        .Where(c => c.Type.Equals("name"))
        .Select(c => c.Value)
        .FirstOrDefault() ?? string.Empty;

    await base.OnInitializedAsync();
  }
}
